﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrderManagement
{
    class Program
    {
        static void Main(string[] args)
        {
            Customers customers1 = new Customers("张小亮", "C3-224", "110");
            Customers customers2 = new Customers("渣渣诚", "C3-319", "119");
            Goods good1 = new Goods("康师傅泡面", 4.5, 12, 2); // 9
            Goods good2 = new Goods("泡面搭档火腿肠", 2, 12, 3); //6
            Goods good3 = new Goods("果粒橙", 4, 12, 1); //4
            Goods good4 = new Goods("营养快线", 5, 12, 2);//10
            List<Goods> goods1 = new List<Goods>();
            List<Goods> goods2 = new List<Goods>();
            List<Goods> goods3 = new List<Goods>();
            goods1.Add(good1);
            goods1.Add(good2);

            goods2.Add(good3);
            goods2.Add(good4);

            goods3.Add(good1);
            goods3.Add(good4);
            OrderDetails orderDetails1 = new OrderDetails(goods1);
            OrderDetails orderDetails2 = new OrderDetails(goods2);
            OrderDetails orderDetails3 = new OrderDetails(goods3);
            //生成测试订单
            Order order1 = new Order(customers1, orderDetails1, "000001");
            Order order2 = new Order(customers2, orderDetails2, "000002");
            Order order3 = new Order(customers1, orderDetails3, "000003");
            Order order4 = new Order(customers2, orderDetails2, "000001");
            List<Order> orders = new List<Order>();
            List<Order> orders1 = new List<Order>();
            OrderService service = new OrderService(orders);

            //以下是具体操作
            try
            {
                service.AddOrder(order2);  //添加订单
                service.AddOrder(order1);
                service.AddOrder(order3);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("排序之前的订单号顺序如下：");
            foreach(Order m in orders)
            {
                Console.Write(m.ID + "  ");
            }
            Console.WriteLine();

            
                

            service.SortOrder((p1, p2) => (int)(p1.OrderDetails.Price - p2.OrderDetails.Price));// 使用lamda表达式自定义排序                                                                                           
            Console.WriteLine("根据lamda表达式排序之后的订单顺序如下：");
            foreach (Order m  in orders)
            {
                Console.Write(m.ID + "  ");
            }
            Console.WriteLine();

            service.SortOrder();  //订单排序，默认是根据订单号
            Console.WriteLine("根据订单号排序之后的订单顺序如下：");
            foreach (Order m in orders)
            {
                Console.Write(m.ID + "  ");
               // Console.WriteLine(m.ToString());
            }
            Console.WriteLine();

            // 查询订单号为00001的订单,以金额为顺序
            try { orders1 = service.OrderCheckID("000001"); }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
           
            // Console.WriteLine("订单ID为000001的订单信息如下：" + orders1[0].ToString());
            foreach (Order m in orders1)
            {
                Console.WriteLine(m.ToString());
            }

            //查询金额不小于15的订单，以金额为顺序
            Console.WriteLine("金额不小于15的订单信息如下：");
            try { orders1 = service.OrderCheckPrice(15, int.MaxValue); }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
            
            foreach(Order m in orders1)
            {
                Console.WriteLine(m.ToString());
            }

            //查询顾客为张小亮的订单，以金额为顺序
            Console.WriteLine("顾客为张小亮的订单如下：");
            try { orders1 = service.OrderCheckName("张小亮"); }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
            foreach(Order m in orders1)
            {
                Console.WriteLine(m.ToString());
            }

            //查询订单中有康师傅泡面的订单，以金额为顺序
            try { orders1 = service.OrderCheckGood("康师傅泡面"); }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            foreach (Order m in orders1)
            {
                Console.WriteLine(m.ToString());
            }

            //未修改之前的订单信息
            Console.WriteLine("未修改之前的订单信息如下：");
            foreach(Order a in orders)
            {
                Console.WriteLine(a.ToString());
            }

            //修改订单
            try { service.ChangeOrder("000001", order4); }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("修改之后的订单信息如下：");
            foreach (Order a in orders)
            {
                Console.WriteLine(a.ToString());
            }

            try { service.AddOrder(order4); }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
            try { service.DeleteOrder("000005"); }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }

            //service.DeleteOrder("000001");//删除订单，根据订单ID进行删除
            //Console.WriteLine(service.GetOrders()[0].ID);
        }
    }
}
